package cn.serein.springboot.sharding.demo.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    //编写新增方法，通过insert注解，指定新增的SQL语句
    //当调用insertOrder方法的时候，等于执行上方注解指定的SQL语句
    //Param注解用于指定新增时的参数
    @Insert("insert into mall_order(buyer_id,buyer_username,order_no,receiver_name) " +
            "values(#{buyerId},#{buyerUsername},#{orderNo},#{receiverName})")
    int insertOrder(@Param("buyerId")Long buyerId,@Param("buyerUsername")String buyerUsername
            ,@Param("orderNo")String orderNo,@Param("receiverName")String receiverName);


    @Select("<script>" +
            "select" +
            " id,buyer_id,buyer_username" +
            " from mall_order " +
            " where id in " +
            "<foreach collection='orderIds' open='(' separator=',' close=')' item='id'>" +
            "#{id} " +
            "</foreach>" +
            "and buyer_id = #{buyerID }" +
            "</script>")
    List<Map> selectOrders(@Param("orderIds") List<Long> orderIds,@Param("buyerID") Long buyerID );

}